﻿using System;
using System.Collections.Generic;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Context;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Service;
using System.Linq;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Script;
using System.Text.RegularExpressions;
using ZyGames.Framework.Net;
using ZyGames.Framework.Common.Serialization;
using ZyGames.DZPocker.Tools;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 申请桌子列表
	/// </summary>
	public class Action30068 : BaseAction
	{
		private string friendsIdStr;
		private List<TableData> _myTableData;
		private string myTableDataStr;
		GameUser _currentGameUser;
		private int userId;
		public Action30068(HttpGet actionGetter)
			: base((short)ActionType.DZGetMyCurrentPlayingTables, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("UserId", ref userId))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			_currentGameUser = GameTable.Current.GetUser(userId);
			if (_currentGameUser == null)
			{
				Tool.WriteWarmingLine("消息30068玩家不存在");
				return false;
			}


			_myTableData = new List<TableData>();
			var tableIds = _currentGameUser.Property.TableIdList;
			if (tableIds.Count > 0)
			{
				foreach (var tableId in tableIds)
				{
					var table = GameRoom.Current.GetTableData(tableId);
					if (table != null)
					{
						if (!_myTableData.Contains(table))
						{
							_myTableData.Add(table);
						}
					}
				}
			}

			myTableDataStr = Convert.ToBase64String(ProtoBufUtils.Serialize(_myTableData));
			return true;
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(this.myTableDataStr);
		}
	}
}
